1-10循环
循环结构¶
In [1]:
tang =0
while tang <10:
print(tang)
tang+=1
In [15]:
tangs=set(['tang','yu','di'])#集合,可变
print(tangs)
while tangs:##只要tangs这是集合不为空就执行
tang=tangs.pop()#弹出
print(tang)
In [26]:
tangs=(['tang','yu','di'])#元组,不可变
tangs
Out[26]:
In [27]:
for name in tangs:
print(name)
In [28]:
tang=[123,345,563,5464,657534]
for i in range(len(tang)):
print(tang[i])
In [29]:
tang=[10,11,12,13,14,15]
for i in tang:
if i%2==0:
print(i)
else:
continue##continue表示之后的继续遍历
print(i)
In [30]:
tang=[10,11,12,13,14,15]
for i in tang:
if i%2==0:
print(i)
else:
break##break表示之后就不遍历了,调出循环
print(i)
In [31]:
tang=set(['tang','yu','di'])
for name in tang:
print(name)
此资源来自https://www.cnblogs.com/AI-robort/,博客园的karina512。